package com.ruoyi.manage.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.manage.domain.ServiceAreaItemVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.manage.domain.ServiceAreaItem;
import com.ruoyi.manage.service.IServiceAreaItemService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 区域服务管理Controller
 * 
 * @author ruoyi
 * @date 2024-05-24
 */
@RestController
@RequestMapping("/areaItem")
public class ServiceAreaItemController extends BaseController
{
    @Autowired
    private IServiceAreaItemService serviceAreaItemService;

    /**
     * 查询区域服务管理列表
     */
    @RequiresPermissions("manage:areaItem:list")
    @GetMapping("/list")
    public TableDataInfo list(ServiceAreaItem serviceAreaItem)
    {
        startPage();
        List<ServiceAreaItem> list = serviceAreaItemService.selectServiceAreaItemList(serviceAreaItem);
        return getDataTable(list);
    }

    /**
     * 导出区域服务管理列表
     */
    @RequiresPermissions("manage:areaItem:export")
    @Log(title = "区域服务管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ServiceAreaItem serviceAreaItem)
    {
        List<ServiceAreaItem> list = serviceAreaItemService.selectServiceAreaItemList(serviceAreaItem);
        ExcelUtil<ServiceAreaItem> util = new ExcelUtil<ServiceAreaItem>(ServiceAreaItem.class);
        util.exportExcel(response, list, "区域服务管理数据");
    }

    /**
     * 获取区域服务管理详细信息
     */
    @RequiresPermissions("manage:areaItem:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(serviceAreaItemService.selectServiceAreaItemById(id));
    }

    /**
     * 新增区域服务管理
     */
    @RequiresPermissions("manage:areaItem:add")
    @Log(title = "区域服务管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ServiceAreaItemVo serviceAreaItemVo)
    {
        int i = serviceAreaItemService.insertServiceAreaItem(serviceAreaItemVo);
        if (i>0){
            return success();
        }else {
            return error("已重复");
        }

    }

    /**
     * 修改区域服务管理
     */
    @RequiresPermissions("manage:areaItem:edit")
    @Log(title = "区域服务管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ServiceAreaItem serviceAreaItem)
    {
        return toAjax(serviceAreaItemService.updateServiceAreaItem(serviceAreaItem));
    }

    /**
     * 删除区域服务管理
     */
    @RequiresPermissions("manage:areaItem:remove")
    @Log(title = "区域服务管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(serviceAreaItemService.deleteServiceAreaItemByIds(ids));
    }



    /**
     * @Author 黄春雨
     * @Description //TODO  修改区域状态
     * @Date 9:23 2024/5/24
     * @Param
     * @param id
     * @param status
     * @return com.ruoyi.common.core.web.domain.AjaxResult
     */
    @RequiresPermissions("manage:areaItem:enabledState")
    @Log(title = "服务类型管理", businessType = BusinessType.UPDATE)
    @PutMapping("/enabledState/{id}/{status}")
    public AjaxResult enabledState(@PathVariable Long id, @PathVariable Long status) {
        return toAjax(serviceAreaItemService.updateEnabledState(id,status));
    }

/**
* @Author 黄春雨
* @Description //TODO 修改热门
* @Date 15:32 2024/5/25
* @Param
 * @param id
 * @param hot
* @return com.ruoyi.common.core.web.domain.AjaxResult
*/
    @RequiresPermissions("manage:areaItem:settingsHot")
    @Log(title = "服务类型管理", businessType = BusinessType.UPDATE)
    @PutMapping("/settingsHot/{id}/{hot}")
    public AjaxResult settingsHot(@PathVariable Long id, @PathVariable Long hot) {
        return toAjax(serviceAreaItemService.updateSettingsHot(id,hot));
    }


    /**
    * @Author 黄春雨
    * @Description //TODO  修改价格
    * @Date 15:33 2024/5/25
    * @Param
     * @param id
     * @param regionalPrice
    * @return com.ruoyi.common.core.web.domain.AjaxResult
    */
    @RequiresPermissions("manage:areaItem:updateRegionalPrice")
    @Log(title = "服务类型管理", businessType = BusinessType.UPDATE)
    @PutMapping("/updateRegionalPrice/{id}/{regionalPrice}")
    public AjaxResult updateRegionalPrice(@PathVariable Long id, @PathVariable Long regionalPrice) {
        return toAjax(serviceAreaItemService.updateRegionalPrice(id,regionalPrice));
    }



}
